"""更新权限表

Revision ID: 397dd0958f6b
Revises: 
Create Date: 2025-04-10 09:44:42.736166

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision: str = '397dd0958f6b'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('ix_image_id', table_name='image')
    op.drop_table('image')
    op.drop_index('ix_product_id', table_name='product')
    op.drop_table('product')
    op.alter_column('permission', 'father_id',
               existing_type=mysql.INTEGER(),
               nullable=False)
    op.drop_constraint('permission_ibfk_1', 'permission', type_='foreignkey')
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_foreign_key('permission_ibfk_1', 'permission', 'permission', ['father_id'], ['id'])
    op.alter_column('permission', 'father_id',
               existing_type=mysql.INTEGER(),
               nullable=True)
    op.create_table('product',
    sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('name', mysql.VARCHAR(length=50), nullable=False),
    sa.Column('attribute', mysql.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('price', mysql.FLOAT(), nullable=False),
    sa.Column('created_at', mysql.DATETIME(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    mysql_collate='utf8mb4_0900_ai_ci',
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.create_index('ix_product_id', 'product', ['id'], unique=False)
    op.create_table('image',
    sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('image_url', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('product_id', mysql.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('created_at', mysql.DATETIME(), nullable=True),
    sa.ForeignKeyConstraint(['product_id'], ['product.id'], name='image_ibfk_1'),
    sa.PrimaryKeyConstraint('id'),
    mysql_collate='utf8mb4_0900_ai_ci',
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.create_index('ix_image_id', 'image', ['id'], unique=False)
    # ### end Alembic commands ###
